<template>
	<view>

		<view class="statisticsWorker_box">
			<view class="statsUser_con">
				<view class="userAvatar">
					<image src="/static/projectIcon.png" mode=""></image>
				</view>
				<view class="userName">{{projectInfo.name}}</view>
				<view class="userStatus">
					{{projectInfo.history==0?'进行中':'已完工'}}
				</view>
			</view>

			<!-- <view class="wageMoney_con">
				<image src="/static/index/moneyIcon2.png" mode=""></image>
				<text>上班：x元/工，加班：x元/小时</text>
			</view> -->

			<view class="projectStats_con">
				<view class="statsList_con">
					<view class="statsItem">
						<view class="statsLabel">总工</view>
						<view class="statsMoney">
							{{projectExtend.total_num}}
							<text >{{projectExtend.work_type==0?'工':'小时'}}</text>
							<!-- +{{projectExtend.overtime_hour}}
							<text v-if="item.overtime_hour>0">H</text> -->
						</view>
					</view>
					<view class="statsLine"></view>
					<view class="statsItem">
						<view class="statsLabel">总工资(元)</view>
						<view class="statsMoney">
							{{projectExtend.total_money}}
						</view>
					</view>
				</view>
				<view class="statsMoney_con">
					<image src="/static/moneyIcon.png" mode=""></image>
					<text>已支付(元)：{{projectExtend.yes_money}}，剩余工资(元)：{{projectExtend.no_money}}</text>
				</view>
			</view>
		</view>

		<!-- 过滤 -->
		<view class="statisticsFilter_box">
			<view class="tabFilter_con">
				<view :class="'tabItem '+(subsectionCurrent==item.id?'active':'')"
					v-for="(item,index) in subsectionList" :key="index" @click="subsectionChange(item.id)">
					{{item.name}}
				</view>
			</view>
			<view class="statisticsFilter_con" v-if="subsectionCurrent>1">
				<!-- 年 -->
				<template v-if="subsectionCurrent==2">
					<u-tabs :list="yearList" :current="yearCurrent" :show-bar="false" inactive-color="#333"
						active-color="#0088FE" bg-color="transparent" @change="yearChange"></u-tabs>
				</template>

				<!-- 月 -->
				<template v-if="subsectionCurrent==3">
					<u-tabs name="name2" :list="monthList" :current="monthCurrent" :show-bar="false"
						inactive-color="#333" active-color="#0088FE" bg-color="transparent" @change="monthChange">
					</u-tabs>
				</template>

				<!-- 自定义 -->
				<view class="customTab_con" v-if="subsectionCurrent==4">
					<view class="customPicker">
						<view class="dateCon" @click="startClick">
							<text v-if="startDate">{{startDate}}</text>
							<text v-else>开始日期</text>
							<u-icon name="arrow-down-fill" color="#666"></u-icon>
						</view>
						<view class="dateLine">至</view>
						<view class="dateCon" @click="endClick">
							<text v-if="endDate">{{endDate}}</text>
							<text v-else>结束日期</text>
							<u-icon name="arrow-down-fill" color="#666"></u-icon>
						</view>
					</view>
				</view>
			</view>
		</view>

		<!-- 工人统计 -->
		
		
		
		<view class="tableOutBox">
			<view class="tableInBox">
				<view class="tableTr">
					<view class="tableTd ">工友姓名</view>
					<view class="tableTd tableTd30">合计</view>
					<view class="tableTd tableTd30">工资</view>
					<view class="tableTd tableTd15">状态</view>
				</view>
				
				<view class="tableTr tableTr2" v-for="(item,index) in memberList" 
							:key="index" >
					<view class="tableTd ">
						<view class="kongItem"></view>
						{{item.userInfo.name}}
					</view>
					<view class="tableTd tableTd2 tableTd30" >
						<view class="kongItem"></view>
						<view class="tableTdItem">
							总<text class="ziOne"></text>工:<text class="color1">{{item.total_num}}{{projectExtend.work_type==0?'工':'小时'}}</text>
						</view>
						<view class="tableTdItem" v-if="item.overtime_hour>0">
							加<text class="ziOne"></text>班:<text class="color1">{{item.overtime_hour}}H</text>
						</view>
						<view class="tableTdItem">
							总工资:<text class="color1">{{item.total_money}}</text>
						</view>
					</view>
					<view class="tableTd tableTd2 tableTd30" >
						<view class="kongItem"></view>
						<view class="tableTdItem">
							已支付:<text class="color2">{{item.yes_money}}</text>
						</view>
						<view class="tableTdItem">
							剩余工资:<text class="color2">{{item.no_money}}</text>
						</view>
					</view>
					<view class="tableTd  tableTd3 tableTd15" >{{item.total_money==item.yes_money?'已结清':'未结清'}}</view>
				</view>
			</view>
		</view>
		
		
		<!-- <view class="workerList_con">
			<view class="workerItem" v-for="(item,index) in memberList" :key="index">
				<view class="workerInfo">
					<view class="projectName">
						<image :src="item.userInfo.header_img" mode=""></image>
						{{item.userInfo.name}}
					</view>
					<view class="settleDoing" v-if="item.total_money == item.yes_money">已结清</view>
					<view class="settleEnd" v-else>未结清</view>
				</view>
				<view class="workerStatistics">
					<view class="workerLi">
						<view class="workerMoney digitFont">{{item.total_num}}</view>
						<view class="workerDesc">总工</view>
					</view>
					<view class="workerLi">
						<view class="workerMoney digitFont">{{item.total_money}}</view>
						<view class="workerDesc">总工资</view>
					</view>
					<view class="workerLi">
						<view class="workerMoney digitFont">{{item.yes_money}}</view>
						<view class="workerDesc">已支付</view>
					</view>
					<view class="workerLi">
						<view class="workerMoney digitFont">{{item.no_money}}</view>
						<view class="workerDesc">剩余工资</view>
					</view>

				</view>
			</view>
		</view> -->
		<view class="dataEmpty_con" v-if="memberList.length==0">
			<u-empty></u-empty>
		</view>
		
		
		<!-- 日期组件：type值单选single、多选multi -->
		<StartDate ref="startDate" type="single" @selected-change="startChange"></StartDate>
		<EndDate ref="endDate" type="single" @selected-change="endChange"></EndDate>
	</view>
</template>

<script>
	import StartDate from "@/components/date/date.vue"
	import EndDate from "@/components/date/date.vue"
	export default {
		components: {
			StartDate,
			EndDate,
		},
		data() {
			return {
				// 类型
				subsectionList: [{
					name: '累计',
					id: '1',
				}, {
					name: '年',
					id: '2',
				}, {
					name: '月',
					id: '3',
				}, {
					name: '自定义',
					id: '4',
				}],
				subsectionCurrent: 1,

				// 年月数据
				yearList: JSON.parse(uni.getStorageSync('yearList')),
				monthList: JSON.parse(uni.getStorageSync('monthListTwo')),
				yearCurrent: -1,
				monthCurrent: -1,

				// 开始日期
				startDate: '',

				// 结束日期
				endDate: '',

				project_id: '',
				memberList: [],
				projectExtend: {},
				projectInfo: {},
				
				calendarShow:false,
			}
		},
		onLoad(option) {
			console.log(option)
			var _this = this;
			if (option.project_id) {
				_this.project_id = option.project_id;
			}
			_this.getWorksiteStatistics();
		},
		methods: {
			// 选项卡
			subsectionChange(index) {
				var _this = this;
				console.log(index)
				_this.subsectionCurrent = index;

				_this.yearCurrent = -1;
				_this.monthCurrent = -1;
				_this.startDate = '';
				_this.endDate = '';

				// 累计
				if (index == 0) {
					_this.getWorksiteStatistics();
				}
			},

			// 选择年
			yearChange(index) {
				var _this = this;
				_this.yearCurrent = index;
				_this.startDate = _this.yearList[_this.yearCurrent].start;
				_this.endDate = _this.yearList[_this.yearCurrent].end;

				_this.getWorksiteStatistics();
			},

			// 选择月
			monthChange(index) {
				var _this = this;
				_this.monthCurrent = index;
				_this.startDate = _this.monthList[_this.monthCurrent].start;
				_this.endDate = _this.monthList[_this.monthCurrent].end;

				_this.getWorksiteStatistics();
			},

			/**
			 * 开始日期 start
			 */
			// 打开选择日期弹窗
			startClick() {
				this.$refs.startDate.calendarShow = true;
			},

			// 日历选中日期事件回调
			startChange(dateStr) {
				console.log(dateStr);
				var _this = this;
				_this.startDate = dateStr;
				_this.getWorksiteStatistics();
			},
			/**
			 * 开始日期 end
			 */

			/**
			 * 结束日期 start
			 */
			// 打开选择日期弹窗
			endClick() {
				this.$refs.endDate.calendarShow = true;
			},

			// 日历选中日期事件回调
			endChange(dateStr) {
				console.log(dateStr);
				var _this = this;
				_this.endDate = dateStr;
				_this.getWorksiteStatistics();
			},
			/**
			 * 结束日期 end
			 */

			// 获取按工地详情
			getWorksiteStatistics() {
				var _this = this;
				console.log(_this.subsectionList)
				console.log(_this.subsectionCurrent)
				var type = _this.subsectionList[_this.subsectionCurrent-1].id;
				// console.log("类型：" + type);
				// console.log("开始日期：" + _this.startDate);
				// console.log("结束日期：" + _this.endDate);

				_this.$u.get('/api/project.monthdata/projectByMember', {
					project_id: _this.project_id,
					type: type,
					start: _this.startDate,
					end: _this.endDate,
				}).then(res => {
					uni.hideLoading();
					_this.memberList = res.data;
					_this.projectExtend = res.extend;
					_this.projectInfo = res.extend.projectInfo;
				}).catch(res => {
					console.log(res);
				})
			},

			// 页面跳转
			goPage(url) {
				uni.navigateTo({
					url: url
				})
			},
		}
	}
</script>

<style scoped lang="scss">
	.statisticsWorker_box {
		padding: 0 30rpx;
		background-color: $uni-color-white;
	}

	.statsUser_con {
		padding: 30rpx 0;
		overflow: hidden;
		display: flex;
		justify-content: space-between;
		align-items: center;
	}

	.userAvatar {
		width: 40rpx;
		height: 40rpx;
		border-radius: 10rpx;
		overflow: hidden;
	}

	.userAvatar image {
		width: 100%;
		height: 100%;
	}

	.userName {
		flex: 2;
		font-size: 28rpx;
		font-weight: bold;
		color: $uni-color;
		margin: 0 20rpx;
	}

	.userStatus {
		width: 100rpx;
		height: 42rpx;
		line-height: 42rpx;
		text-align: center;
		font-size: 24rpx;
		color: #FF4241;
		background: #FFEBEB;
		border-radius: 8rpx;
		overflow: hidden;
	}

	.wageMoney_con {
		padding-bottom: 30rpx;
		overflow: hidden;
		display: flex;
		align-items: center;
	}

	.wageMoney_con image {
		width: 30rpx;
		height: 30rpx;
	}

	.wageMoney_con text {
		font-size: 28rpx;
		color: $uni-color;
		margin-left: 20rpx;
	}

	.projectStats_con {
		overflow: hidden;
	}

	.statsList_con {
		height: 200rpx;
		background: #f0f6ff;
		border: 2rpx solid #cce0ff;
		border-radius: 10rpx 10rpx 0 0;
		box-sizing: border-box;
		overflow: hidden;
		display: flex;
		justify-content: space-between;
		align-items: center;
	}

	.projectStats_con .statsItem {
		flex: 1;
		text-align: center;
	}

	.projectStats_con .statsLabel {
		font-size: 28rpx;
		color: #8B8A90;
	}

	.projectStats_con .statsMoney {
		font-size: 54rpx;
		font-weight: bold;
		color:#000;
		margin-top: 20rpx;
	}

	.projectStats_con .statsMoney text {
		font-size: 28rpx;
	}

	.projectStats_con .statsLine {
		width: 2rpx;
		height: 60rpx;
		background-color: #CCE0FF;
	}

	.projectStats_con .statsMoney_con {
		height: 90rpx;
		padding: 0 30rpx;
		background: #327fe8;
		border-radius: 0 0 10rpx 10rpx;
		box-sizing: border-box;
		overflow: hidden;
		display: flex;
		align-items: center;
	}

	.projectStats_con .statsMoney_con image {
		width: 30rpx;
		height: 30rpx;
	}

	.projectStats_con .statsMoney_con text {
		font-size: 28rpx;
		color: #fff;
		margin-left: 20rpx;
	}

	// 过滤
	.statisticsFilter_box {
		background-color: $uni-color-white;
		overflow: hidden;
		margin: 20rpx 0;
	}

	.tabFilter_con {
		display: flex;
		justify-content: space-between;
		align-items: center;
	}

	.tabItem {
		flex: 1;
		height: 90rpx;
		line-height: 90rpx;
		font-size: 28rpx;
		font-weight: bold;
		color: $uni-color;
		text-align: center;
		border-bottom: 4 solid #fff;
		box-sizing: border-box;
	}

	.tabItem.active {
		border-bottom: 4rpx solid $uni-color-active;
	}

	.statisticsFilter_con {
		padding: 20rpx 0 0rpx 0;
		border-top: 1rpx solid #eee;
		overflow: hidden;
	}

	.customTab_con {
		overflow: hidden;
		display: flex;
		justify-content: space-between;
		align-items: center;
	}

	.customPicker {
		display: flex;
		align-items: center;
	}

	.dateCon {
		display: flex;
		justify-content: center;
		align-items: center;
	}

	.dateCon text {
		font-size: 28rpx;
		color: #333;
		margin-right: 10rpx;
	}

	.dateLine {
		color: #333;
		margin: 0 30rpx;
	}

	// 工地统计
	.worksiteInfo_con {
		height: 224rpx;
		padding: 0 30rpx;

		background-size: contain;
		box-sizing: border-box;
		overflow: hidden;
		margin: 30rpx 0;
	}

	.statisticsCon {
		overflow: hidden;
		padding-top: 20rpx;
		display: flex;
		justify-content: flex-start;
		align-items: center;
	}

	.statisticsItem {
		flex: 1;
	}

	.statisticsMoney {
		font-size: 30rpx;
		color: #fff;
	}

	.statisticsDesc {
		font-size: 24rpx;
		color: #BCDEFD;
		margin-top: 10rpx;
	}

	// 工地统计
	.workerList_con {
		padding: 0 30rpx;
	}
	
	.workerItem {
		overflow: hidden;
	}
	
	.workerInfo {
		padding: 30rpx 0;
		overflow: hidden;
		display: flex;
		justify-content: space-between;
		align-items: center;
	}
	
	.projectName {
		font-size: 28rpx;
		font-weight: bold;
		color: #000;
		margin-right: 20rpx;
		float: left;
		width: 400rpx;
		line-height: 34rpx;
	}
	
	.projectName image {
		width: 34rpx;
		height: 34rpx;
		vertical-align: top;
		margin: 0rpx 10rpx 0 0;
	}
	
	.settleDoing {
		width: 100rpx;
		height: 42rpx;
		line-height: 42rpx;
		text-align: center;
		font-size: 24rpx;
		color: #06C158;
		background: #EBFFF3;
		border-radius: 8rpx;
		overflow: hidden;
	}
	
	.settleEnd {
		width: 100rpx;
		height: 42rpx;
		line-height: 42rpx;
		text-align: center;
		font-size: 24rpx;
		color: #FC7032;
		background: #FFF1EB;
		border-radius: 8rpx;
		overflow: hidden;
	}
	
	.workerStatistics {
		padding: 30rpx 0;
		background: $uni-color-white;
		border-radius: 10rpx;
		display: flex;
		justify-content: space-around;
		align-items: center;
	}
	
	.workerLi {
		flex: 1;
		text-align: center;
	}
	
	.workerMoney {
		font-size: 40rpx;
		color: #000;
	}
	
	.workerDesc {
		font-size: 24rpx;
		color: #999;
		margin-top: 20rpx;
	}
	
	
	
	//表格
	.tableOutBox{
		background-color: #dae1e8;
		border-left: 2rpx solid #e2e2e2;
		border-top: 2rpx solid #e2e2e2;
		box-sizing: border-box;
		width: 690rpx;
		margin: 0rpx auto;
		border-radius: 10rpx;
		overflow: hidden;
	}
	
	.tableInBox{
		background-color: #fff;
		border-radius: 10rpx;
	}
	.tableTr{
		height: 90rpx;
		line-height: 90rpx;
		overflow: hidden;
		background-color: #f7fbfe;
		border-bottom: 2rpx solid #e2e2e2;
	}
	.tableTr2{
		min-height: 170rpx;
		line-height: 50rpx;
		text-align: left;
		font-size: 28rpx;
		font-weight: 400;
		box-sizing: border-box;
	}
	.tableTr:nth-child(2n){
		background-color: #ffff;
	}
	.tableTd{
		width: 25%;
		height: 100%;
		text-align: center;
		padding-left: 10rpx;
		float: left;
		font-size: 26rpx;
		font-weight: bold;
		border-right: 2rpx solid #e2e2e2;
	}
	.tableTd2{
		text-align: left;
		padding-left: 10rpx;
		font-weight: 400;
		font-size: 26rpx;
		color: #333;
	}
	.tableTd3{
		text-align: center;
		line-height: 170rpx;
		color: #327fe8;
		font-size: 26rpx;
		padding-left: 0rpx;
	}
	.color1{
		color: #ff6600;
	}
	.color2{
		color: #35c700;
	}
	
	.tableTd10{
		width: 10%;
	}
	.tableTd15{
		width: 15%;
	}
	.tableTd20{
		width: 20%;
	}
	.tableTd30{
		width: 30%;
	}
	.tableTd35{
		width: 35%;
	}
	.kongItem{
		width: 100%;
		height: 10rpx;
	}
	.ziOne{
		padding-left: 28rpx;
	}
</style>
